<?php

use console\db\Migration;

/**
 * 创建意见反馈相关信息表
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m150104_091358_t_feedback extends Migration {

    /**
     * {@inheritdoc}
     */
    public function up() {

        /**
         * 意见反馈场景表
         * @table `feedback_scene`
         */
        $this->tableBuilder([
            'name' => 'feedback_scene',
            'comment' => '意见反馈场景表',
            'columns' => [
                'id' => $this->primaryKey(),
                'parent_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('父级场景ID'),
                'name' => $this->string(50)->notNull()->comment('场景或问题名称'),
                'description' => $this->string(255)->defaultValue('')->comment('说明描述'),
                'listorder' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('显示排序'),
                'status' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);

        /**
         * 意见反馈表
         * @table `feedback`
         */
        $this->tableBuilder([
            'name' => 'feedback',
            'comment' => '意见反馈表',
            'columns' => [
                'id' => $this->primaryKey(),
                'user_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('反馈用户ID'),
                'scene_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('应用场景ID'),
                'content' => $this->string(255)->notNull()->comment('反馈内容'),
                'mobile' => $this->char(11)->defaultValue('')->comment('手机号'),
                'device_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('备注'),
                'ip' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('备注'),
                'accept_status' => $this->tinyint(1)->unsigned()->notNull()->defaultValue(0)->comment('受理状态'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);

        /**
         * 意见反馈处理表
         * @table `feedback_opinion`
         */
        $this->tableBuilder([
            'name' => 'feedback_opinion',
            'comment' => '意见反馈处理表',
            'columns' => [
                'id' => $this->primaryKey(),
                'feedback_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('反馈意见ID'),
                'admin_id' => $this->integer(11)->unsigned()->notNull()->defaultValue(0)->comment('受理人ID'),
                'mark' => $this->string(255)->notNull()->comment('处理备注'),
                'status' => $this->tinyint(1)->notNull()->defaultValue(10)->comment('状态'),
                'created_at' => $this->unixTimestamp()->comment('创建时间'),
                'updated_at' => $this->unixTimestamp()->comment('更新时间'),
            ]
        ]);
    }

    /**
     * {@inheritdoc}
     */
    public function down() {
        $this->dropTable('{{%feedback_opinion}}');
        $this->dropTable('{{%feedback}}');
        $this->dropTable('{{%feedback_scene}}');
    }

}
